﻿using SAIM.Models.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//Se usara el AttachmentsDAL para cargar los datos del DAL

namespace SAIM.Models.BLL
{
    public class DownloadsBLL : IDisposable
    {
        private SAIMEntities db;
        private eVirtualEntities eVirtual;
        private List<AttachmentsDAL> _value;
        /// <summary>
        /// Dirección relativa en donde se guardan todos los archivos
        /// </summary>
        public static string PathForSaving
        {
            get
            {
                return "~/App_Data/SAIM_Uploads/";
            }
        }

        public DownloadsBLL()
        {
            db = new SAIMEntities();
            eVirtual = new eVirtualEntities();
        }

        /// <summary>
        /// Contiene la información de todos los archivos adjuntos
        /// </summary>
        private List<AttachmentsDAL> Value
        {
            get { return (_value = _value ?? db.Attachments.ToList()); }
            set { _value = value; }
        }

        public void GetAttachmentName(string Name, ref string filePath, ref string fileName)
        {
            AttachmentsDAL attachment = Value.FirstOrDefault(a =>
                (a.Mask == Name) 
            );

            if (attachment != null)
            {
                filePath = attachment.FilePath;
                fileName = attachment.Name;
            }
            else
            {
                filePath = fileName = string.Empty;
            }
        }


        public void Dispose()
        {
            db.Dispose();
        }
    }
}